package cn.iocoder.boot.learn_200712_springmvc2.learn.controller;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/response")
@Controller
public class ResponseController {
    @RequestMapping("/returnHtmlPage")
    public String returnHtmlPage() {
        return "/hello.html";
    }

    @ResponseBody
    @RequestMapping("/setHeader")
    public String setHeader(HttpServletResponse response) {
        response.setHeader("myKey", "myValue");

        // 设置 Cookie
        Cookie cookie = new Cookie("myKey", "myValue");
        response.addCookie(cookie);

        return "success";
    }
}
